home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18006 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.os.ms-windows.programmer.tools.misc,comp.os.ms-windows.programmer.win32,comp.os.ms-windows.programmer.misc,comp.lang.c++
  4. Subject: Re: [Q] Why doesn't this compile?
  5. Date: Thu, 18 Apr 1996 10:19:36 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <31764F78.4259@datalytics.com>
  8. References: <317523C0.5042@eps.agfa.be> <4l3cpv$l74@helium.einet.net>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. John Arisco wrote:
  16. > Ranko Orlic <rorlic@eps.agfa.be> wrote:
  17. > >Using MSVC 4.0 compiler I get the following:
  18. > >File test.cpp: ---------------------------------
  19. > >class A {
  20. > >public:
  21. > >       class L {
  22. > >       public:
  23. > >               L() {}
  24. > >               virtual void f() {
  25. > >                       int dummy = 0;
  26. > >               }
  27. > >       };
  28. > >       A();
  29. > >};
  30. > >class B : public A {
  31. > >       class L : public A::L {
  32. > >       public:
  33. > >               L() {}
  34. > >               virtual void f() {
  35. > >                       A::L::f();
  36. > >               }
  37. > >       };
  38. > >       B();
  39. > >};
  40. > >Compilation result: ----------------------------
  41. > >test.cpp(18) : error C2352: 'A::L::f' : illegal call of
  42. > >nonstatic member function
  43. > >Error executing cl.exe.
  44. > >test.obj - 1 error(s), 1 warning(s)
  45. > [snip]
  46. > You cannot call a non-static member function without specifying
  47. > an object.  The way you've written this, there is no way for B::L::f()
  48. > to set its "this" pointer.  Of course, if this is really what you want
  49. > to do, the declaration of B::L::f() is unnecessary, since B::L
  50. >  inherits the A::L::f() virtual method from its base class.
  51.  
  52. That's nonsensical.  We're talking class declarations here.  
  53. B::L::f is a non-static member function of B::L, so it has a 
  54. this pointer.
  55.  
  56. I moved A::L out of A, making it just L, and I changed B::L to 
  57. B::BL, and it compiled fine.  Then I thought, could it be the 
  58. names were causing a problem?  So, I moved L back into A, but 
  59. left BL as is.  I got the original error.  I also moved BL out 
  60. of B, leaving L nested in A.  I got the original error.  
  61. Finally, I made both functions f non-inline.  I got the 
  62. original error.  Clearly, the problem has to do with deriving 
  63. from a nested class.
  64.  
  65. I don't think that should be a problem, but clearly VC doesn't 
  66. handle it.  So, I decided to try another compiler.  Compiling 
  67. under Silicon Graphics' C++ (NCC) v4.0.  This isn't enough to 
  68. justify my interpretation that it should work, but it is 
  69. comforting.
  70.  
  71. BTW, I did a cursory examination of the Jan DWP and found 
  72. nothing to suggest that it shouldn't work.
  73.  
  74. -- 
  75. Robert Stewart        | My opinions are usually my own.
  76. Datalytics, Inc.    | stew@datalytics.com
  77.